import router from '@/router'
import store from '@/store'

/**
 * 是否有权限
 * @param {*} key
 */
export function isAuth (key) {
  return store.getters['menu/getPermission'].indexOf(key) > -1 || false
}

/**
 * 退出登录，清除登录信息
 */
export function logout () {
  store.dispatch('user/clean_LoginInfo')
  router.options.isAddDynamicMenuRoutes = false
}

export function filterMenuData (dataList, type) {
  let retList = []
  retList = dataList.filter((item) => {
    return (item.type < (type))
  })
  retList.forEach((item) => {
    if (item.children.length > 0) {
      let newList = filterMenuData(item.children, type)
      item.children = newList
    }
  })
  return retList
}
